<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <style>
        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }
        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>权限管理<small>菜单管理</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>权限管理</el-breadcrumb-item>
            <el-breadcrumb-item>菜单管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">

        <div class="filter-container">
            <el-input placeholder="菜单标题" v-model="pagination.queryString" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter"></el-input>
            <el-button @click="findPage()" class="dalfBut">查询</el-button>
            <el-button type="primary" size="mini" @click="createNewMenu()">新建菜单</el-button></template>

        </div>

        <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
            <el-table-column type="index" align="center" label="序号"></el-table-column>
            <el-table-column prop="name" label="菜单标题" align="center"></el-table-column>

            <el-table-column prop="linkUrl" label="链接地址" align="center"></el-table-column>
            <el-table-column prop="path" label="标题级别" align="center"></el-table-column>
            <el-table-column prop="level" label="等级" align="center"></el-table-column>
            <el-table-column label="操作" align="center">
                <template slot-scope="scope">
                    <el-button type="primary" size="mini" @click="handleCreate(scope.row)">角色管理</el-button>
                    <el-button type="primary" size="mini" @click="edit(scope.row)">修改菜单</el-button>
                </template>

            </el-table-column>
        </el-table>
        <div class="pagination-container">
            <el-pagination
                    class="pagiantion"
                    @current-change="handleCurrentChange"
                    :current-page="pagination.currentPage"
                    :page-size="pagination.pageSize"
                    layout="total, prev, pager, next, jumper"
                    :total="pagination.total">
            </el-pagination>
        </div>




        <div class="add-form">
            <el-dialog title="新建菜单" :visible.sync="newMenu" :if="newMenu">
                <template>
                    <el-tabs v-model="activeName" type="card">
                        <el-tab-pane label="基本信息" name="first">
                            <el-form label-position="right" label-width="100px">
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="菜单名">
                                            <el-input v-model="formData.name"/>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="链接地址">
                                            <el-input v-model="formData.linkUrl"/>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="等级">
                                            <el-select v-model="formData.level">
                                                <el-option label="1级菜单" value="1"></el-option>
                                                <el-option label="2级菜单" value="2"></el-option>
                                            </el-select>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="级别名">
                                            <el-input v-model="formData.path"/>
                                        </el-form-item>
                                    </el-col>

                                </el-row>

                                <el-col :span="12">
                                    <el-form-item label="图标">
                                        <el-select v-model="formData.description">
                                            <el-option label="图片类" value="el-icon-picture"></el-option>
                                            <el-option label="信件类" value="el-icon-picture-outline"></el-option>
                                            <el-option label="消息类" value="el-icon-s-comment"></el-option>
                                            <el-option label="加锁类" value="el-icon-lock"></el-option>
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="备注">
                                        <el-input v-model="formData.remark" type="input"></el-input>
                                    </el-form-item>
                                </el-col>

                            </el-form>
                        </el-tab-pane>
                    </el-tabs>
                </template>
                <div slot="footer" class="dialog-footer">
                    <el-button @click="newMenu = false">取消</el-button>
                    <el-button type="primary" @click="commitNewMenu()">确定</el-button>
                </div>
            </el-dialog>
        </div>




        <div class="add-form">
            <el-dialog title="修改菜单信息" :visible.sync="editMenu" :if="editMenu">
                <template>
                    <el-tabs v-model="activeName" type="card">
                        <el-tab-pane label="基本信息" name="first">
                            <el-form label-position="right" label-width="100px">
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="菜单名">
                                            <el-input v-model="formData.name"/>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="链接地址">
                                            <el-input v-model="formData.linkUrl"/>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="等级">
                                            <el-select v-model="formData.level">
                                                <el-option label="1级菜单" value="1"></el-option>
                                                <el-option label="2级菜单" value="2"></el-option>
                                            </el-select>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="级别名">
                                            <el-input v-model="formData.path"/>
                                        </el-form-item>
                                    </el-col>

                                </el-row>

                                <el-col :span="12">
                                    <el-form-item label="图标">
                                        <el-select v-model="formData.description">
                                            <el-option label="图片图标" value="el-icon-picture"></el-option>
                                            <el-option label="图标2" value="fa-user-md"></el-option>
                                            <el-option label="图标3" value="fa-tty"></el-option>
                                            <el-option label="图标4" value="fa-stethoscope"></el-option>
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="备注">
                                        <el-input v-model="formData.remark" type="input"></el-input>
                                    </el-form-item>
                                </el-col>

                            </el-form>
                        </el-tab-pane>
                    </el-tabs>
                </template>
                <div slot="footer" class="dialog-footer">
                    <el-button @click="editMenu = false">取消</el-button>
                    <el-button type="primary" @click="commitEditMenu()">确定</el-button>
                </div>
            </el-dialog>
        </div>










        <!-- 新增标签弹层 -->
        <div class="add-form">
            <el-dialog title="角色管理" :visible.sync="dialogFormVisible" :if="dialogFormVisible">
                <template>
                    <el-tabs v-model="activeName" type="card">

                        <div class="checkScrol">
                            <table class="datatable">
                                <thead>
                                <tr>

                                    <th>序号</th>
                                    <th>角色名</th>
                                    <th>角色关键字</th>
                                    <th>选择</th>

                                </tr>
                                </thead>
                                <tbody>
                                <tr v-for="(c,index) in tableData">
                                    <td>
                                        <input :id="c.id" v-model="roleIds" type="checkbox" :value="c.id">
                                    </td>

                                    <td><label :for="c.id">{{index+1}}</label></td>
                                    <td><label :for="c.id">{{c.name}}</label></td>
                                    <td><label :for="c.id">{{c.keyword}}</label></td>
                                    <td><label :for="c.id">{{c.description}}</label></td>


                                </tr>
                                </tbody>
                            </table>
                        </div>

                    </el-tabs>
                </template>
                <div slot="footer" class="dialog-footer">
                    <el-button @click="dialogFormVisible = false">取消</el-button>
                    <el-button type="primary" @click="handleAdd()">确定</el-button>
                </div>
            </el-dialog>
        </div>


    </div>

</div>

</body>

<script>
    var vue = new Vue({
        el: '#app',
        data:{
            editMenu:false,
            newMenu:false,
            menuId:0,
            addUserWindow:false,
            activeName:'first',//添加/编辑窗口Tab标签名称
            pagination: {//分页相关属性
                currentPage: 1,
                pageSize:10,
                total:100,
                queryString:null,
            },
            dataList: [],//列表数据
            formData: {},//表单数据
            tableData:[],//新增和编辑表单中对应的检查项列表数据
            roleIds:[],//新增和编辑表单中检查项对应的复选框，基于双向绑定可以进行回显和数据提交
            dialogFormVisible: false,//控制添加窗口显示/隐藏
            dialogFormVisible4Edit:false,//控制编辑窗口显示/隐藏
            rules: {//校验规则
                username: [{ required: true, message: '项目编码为必填项', trigger: 'blur' }],
                password: [{ required: true, message: '项目名称为必填项', trigger: 'blur' }]
            }
        },
        created() {
            this.findPage();
        },
        methods: {

            edit(row){
                this.editMenu=true;

                axios.get("/menu/findMenuById.do?menuId="+row.id).then((res) => {
                    if(res.data.flag){
                        // this.$message({
                        //     type:'success',
                        //     message:res.data.message
                        // });
                        this.formData=res.data.data
                    }else{
                        //操作失败
                        this.$message.error(res.data.message);
                    }
                })

            },


            commitEditMenu(){
                axios.post("/menu/editMenu.do",this.formData).then((res) => {

                    if(res.data.flag){
                        this.$message({
                            type:'success',
                            message:res.data.message
                        });
                        this.$confirm("您需要现在重新刷新菜单栏吗?","提示",{
                            type:"info"
                        }).then(()=>{
                            window.parent.location.reload();
                        }).catch(()=>{
                                this.findPage();
                                this.editMenu = false;
                            }

                        )



                    }else{
                        //操作失败
                        this.$message.error(res.data.message);
                    }
                })

            },






            //添加

            //分页查询
            findPage(page) {
                if(this.pagination.queryString!=null && this.pagination.queryString!=""){
                    this.pagination.currentPage=1;
                }
                var parms={
                    currentPage:this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    queryString:this.pagination.queryString
                };
                axios.post("/menu/findPage.do",parms).then(res=>{
                    vue.dataList=res.data.rows;
                    vue.pagination.total=res.data.total
                })

            },
            // 重置表单
            resetForm() {
                this.formData = {};
            },
            createNewMenu(){
                this.newMenu=true;
            },

            commitNewMenu(){
                if(this.formData.name==null || this.formData.name==""){
                    this.$message.error("请填写菜单名")
                    return false;
                }

                axios.post("/menu/CreateNewMenu.do",this.formData).then((res) => {

                    if(res.data.flag){
                        this.$message({
                            type:'success',
                            message:res.data.message
                        });
                        this.$confirm("您需要现在重新刷新菜单栏吗?","提示",{
                            type:"info"
                        }).then(()=>{
                            window.parent.location.reload();
                        }).catch(()=>{
                                this.findPage();
                                this.editMenu = false;
                            }

                        )
                    }else{
                        //操作失败
                        this.$message.error(res.data.message);
                    }
                })


            },




            // 弹出添加窗口
            handleCreate(row) {
                this.resetForm();
                this.dialogFormVisible = true;
                // this.activeName = 'first';
                this.roleIds = [];
                // alert(row.id)
                this.menuId=row.id;

                //SELECT * FROM t_role   WHERE  id  NOT  IN  (SELECT role_id FROM `t_user_role` WHERE user_id =1)

                axios.get("/menu/findAllRole.do").then((res) => {
                    if(res.data.flag){
                        vue.tableData = res.data.data;

                        axios.get("/menu/findRolesIdByMenuId.do?menuId="+row.id).then(res=>{

                            this.roleIds=res.data.data
                        }).catch()


                    }else{
                        vue.$message.error(res.data.message);
                    }
                });
            },


            //切换页码
            handleCurrentChange(currentPage) {
                //为模型数据赋值（当前页面）
                this.pagination.currentPage = currentPage;
                this.findPage();
            },

            addUser(){
                this.addUserWindow=true
            },
            handleAdd(){

               axios.get("/menu/updateRoleByMenuId.do?menuId="+this.menuId+"&&roleIds="+this.roleIds).then(res=>{

                   if (res.data.flag) {
                       this.$message({
                           message: res.data.message,
                           type: "success"
                       })
                   } else {
                       this.$message.error(res.data.message)
                   }

               }).finally(()=>{
                   this.dialogFormVisible=false
                   this.findPage()
               })

            },



            decide(){


                axios.post("/user/addUser.do", this.formData).then(res => {
                    if (res.data.flag) {
                        this.$message({
                            message: res.data.message,
                            type: "success"
                        })
                    } else {
                        this.$message.error(res.data.message)
                    }
                }).catch().finally(()=>{
                    this.addUserWindow=false;
                })
            }

        },





    })
</script>
</html>
